const Koa = require('koa')
const Router = require('koa-router')
const serve = require('koa-static')
const app = new Koa()
const router = new Router()

app
	.use(serve(__dirname + '/dist'))
	.use(router.routes())
  .use(router.allowedMethods())

router.all('*', function(ctx, next) {
	// console.log(ctx.request.header.origin)
  ctx.set("Access-Control-Allow-Origin", "http://localhost:8080")
  ctx.set("Access-Control-Allow-Headers", "X-Requested-With")
  ctx.set("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
  ctx.set("X-Powered-By",' 3.2.1')
  ctx.set("Content-Type", "application/json; charset=utf-8")
  next();
});

router.get('/document/:id', (ctx, next) => {
	console.log('id: ' + ctx.params.id)
	ctx.body = {id: ctx.params.id}
})
app.listen(3002)
 
console.log('listening on port 3002')